package com.example.crm_system.controller;

import com.example.crm_system.config.Result;
import com.example.crm_system.entity.Business;
import com.example.crm_system.entity.Params;
import com.example.crm_system.service.BusinessService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business")
public class BusinessController {
    @Resource
    private BusinessService businessService;

    // 插入business
    @PostMapping("/insert")
    public Result insert(@RequestBody Business business) {
        if (business.getBno() == null) {
            businessService.insert(business);
        } else {
            businessService.update(business);
        }
        return Result.success();
    }

    // 删除business
    @DeleteMapping("/delete/{bno}")
    public Result delete(@PathVariable Integer bno) {
        businessService.delete(bno);
        return Result.success();
    }

    // 查询所有business
    @GetMapping("/selectAll")
    public List<Business> selectAll() {
        return businessService.selectAll();
    }

    // 通过bno查询business
    @GetMapping("/selectByBno/{bno}")
    public List<Business> selectByBno(@PathVariable Integer bno) {
        return businessService.selectByBno(bno);
    }

    // 查询方法
    @GetMapping("/searchBusiness")
    public Result searchBusiness(Params params) {
        PageInfo<Business> list = businessService.searchBusiness(params);
        return Result.success(list);
    }
}
